xquery version "1.0-ml";

module namespace tags = "http://www.porvino.com/tags";

declare function get-tag-controls( $cid as xs:string, $host as xs:string, $did as xs:string, $dbase as xs:string) {
     <span>
         <a class="addTag"
            id="addTag{$cid}"
            onclick="tags.addTagClickHandler('{$cid}','{$host}','{$did}','{$dbase}');">
            add tag   
         </a> 
         <input class=""
            id="addTagInput{$cid}"
            type="text"
            style="width: 120px">
         </input>
         
         
         <!--
            TODO add existing tag controls: list each tag, include an x icon to delete, add delete control 
         -->
         <div id="tagList{$cid}">
        {
            let $doc := xdmp:eval(fn:concat("fn:doc('",$did,"')",$dbase))
            return
                for $tag in $doc/tags/tag/text()
                return
                tags:get-tag-control($cid, $host, $did, $dbase, $tag)
        }
        </div>
     </span>
};

declare function get-tag-control( $cid as xs:string, $host as xs:string, $did as xs:string, $dbase as xs:string, $tag as xs:string) {
    <span id="tag{$cid}{$tag}">
        <span>{$tag}</span>
        <img 
            id="deleteTag{$cid}{$tag}"
            src="{$host}/images/cancel_off.png"
            onclick="tags.deleteTagClickHandler('{$cid}','{$host}','{$did}','{$dbase}','{$tag}');">
        </img>
    </span>

};



